package cn.zkrt.iotms.module.iot.controller;

import cn.zkrt.iotms.comm.R;
import cn.zkrt.iotms.module.iot.entity.DeviceTypeAttributeB;
import cn.zkrt.iotms.module.iot.service.DeviceTypeAttributeBService;
import cn.zkrt.iotms.module.iot.vo.DeviceTypeAttributeBVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DeviceTypeAttributeB)表控制层
 *
 * @author xulinyu
 * @since 2024-09-28 16:33:34
 */
@Api(tags = "2设备类型属性")
@RestController
@RequestMapping("deviceTypeAttributeB")
public class DeviceTypeAttributeBController {
    /**
     * 服务对象
     */
    @Resource
    private DeviceTypeAttributeBService deviceTypeAttributeBService;

    /**
     * 分页查询
     *
     * @param typeAttributeName 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public R<Page<DeviceTypeAttributeBVO>> queryByPage(Page<DeviceTypeAttributeBVO> page, String typeAttributeName) {
        return R.data(deviceTypeAttributeBService.pageList(page,typeAttributeName));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R<DeviceTypeAttributeB> queryById(@PathVariable("id") Long id) {
        return R.data(this.deviceTypeAttributeBService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param deviceTypeAttributeB 实体
     * @return 新增结果
     */
    @PostMapping
    public R<Boolean> add(@Validated @RequestBody DeviceTypeAttributeB deviceTypeAttributeB) {
        return R.data(this.deviceTypeAttributeBService.add(deviceTypeAttributeB));
    }

    /**
     * 编辑数据
     *
     * @param deviceTypeAttributeB 实体
     * @return 编辑结果
     */
    @PutMapping
    public R<Boolean> edit(@Validated @RequestBody DeviceTypeAttributeB deviceTypeAttributeB) {
        //不能改所属类型
        deviceTypeAttributeB.setDeviceTypeId(null);
        return R.data(this.deviceTypeAttributeBService.updateById(deviceTypeAttributeB));
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return 删除是否成功
     */
    @DeleteMapping
    public R<Boolean> deleteByIds(@RequestParam("idList") List<String> idList) {
        return R.data(this.deviceTypeAttributeBService.deleteByIds(idList));
    }

}

